﻿using System;
using System.Web;
using System.Collections.Generic;
using System.Text;

namespace MyWebPagesStarterKit
{
    public class CodeColorizer : Section<CodeColorizer.Data>
    {
        public CodeColorizer() : base(){}
        public CodeColorizer(string id) : base(id) { }

        public string Html
        {
            get { return _data.Html; }
            set { _data.Html = value; }
        }

        public string Code
        {
            get { return _data.Code; }
            set { _data.Code = value; }
        }

        public override List<SearchResult> Search(string searchString, WebPage page)
        {
            List<SearchResult> foundResults = new List<SearchResult>();
            if ((HttpUtility.HtmlDecode(SearchResult.RemoveHtml(Html))).IndexOf(searchString, StringComparison.CurrentCultureIgnoreCase) > -1)
                foundResults.Add(new SearchResult(
                    string.Format("~/Default.aspx?pg={0}#{1}", page.PageId, SectionId),
                    page.Title,
                    SearchResult.CreateExcerpt((HttpUtility.HtmlDecode(SearchResult.RemoveHtml(Html))), searchString))
                );
            foundResults.Sort();

            return foundResults;
        }

        public override bool IsOnline
        {
            get{return _data.IsOnline;}
            set{_data.IsOnline = value;}
        }
        public override Position Position
        {
            get
            {
                return _data.Position;
            }
            set
            {
                _data.Position = value;
            }
        }
        
        public class Data
        {
            public bool IsOnline = false;
            public string Code = string.Empty;
            public string Html = string.Empty;
            public Position Position;
        }
    }
}
